package com.sairobo.admin.modules.srblive.manager.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.sairobo.base.common.entity.Page;
import com.sairobo.base.common.constant.QueryConts;
import com.sairobo.base.common.entity.Query;
import com.sairobo.admin.modules.srblive.dao.SrbliveUserMapper;
import com.sairobo.admin.modules.srblive.entity.SrbliveUser;
import com.sairobo.admin.modules.srblive.manager.SrbliveUserManager;

/**
 * 用户信息
 *
 * @author admin
 * @email sairobo
 * @url www.sairobo.com
 * @date 2018年1月11日 上午11:05:49
 */
@Component("srbliveUserManager")
public class SrbliveUserManagerImpl extends ServiceImpl<SrbliveUserMapper,SrbliveUser> implements SrbliveUserManager {
    
	@Override
	public List<SrbliveUser> listSrbliveUser(Page<SrbliveUser> page, Query search) {
        EntityWrapper<SrbliveUser> ew=new EntityWrapper<SrbliveUser>();
        Map map = (HashMap)search.get(QueryConts.SEARCH_KEYWORD);
        String key = (String) map.get("key");
        if(StringUtils.isNotEmpty(key)){
            ew.andNew();
            ew.like(true,"nickName",key);
            ew.or();
            ew.like(true,"province",key);
            ew.or();
            ew.like(true,"city",key);
        }


        return baseMapper.selectPage(page,ew);
	}

	@Override
	public int saveSrbliveUser(SrbliveUser srbliveUser) {
        return baseMapper.insert(srbliveUser);
	}

	@Override
	public SrbliveUser getSrbliveUserById(Long id) {
        SrbliveUser test = baseMapper.selectById(id);
        return test;
	}

	@Override
	public int updateSrbliveUser(SrbliveUser srbliveUser) {
        return baseMapper.updateById(srbliveUser);
	}

	@Override
	public int batchRemove(Long[] id) {
        int count = baseMapper.deleteBatchIds(Arrays.asList(id));
        return count;
	}
	
}
